package com.one.consumer.order.ui;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.utils.PayUtils;
import com.one.common.view.base.IListView;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseListActivityC;
import com.one.consumer.order.model.item.OrderEmptyItem;
import com.one.consumer.order.presenter.OrderPresenter;
import com.one.consumer.order.ui.binder.CustomOrderBinder;
import com.one.consumer.order.ui.binder.DEOrderBinder;
import com.one.consumer.order.ui.binder.OrderEmptyBinder;
import com.one.common.common.order.extra.ReserveExtra;
import com.one.consumer.reserve.model.item.CustomItem;
import com.one.consumer.reserve.model.item.ReserveItem;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/27 3:54 PM
 * description ：定制加配，装修订单列表
 **/
@Route(path = RouterPath.DE_CU_ORDER)
public class DeCuOrderListActivity extends BaseListActivityC<OrderPresenter> implements IListView{
    private ReserveExtra extra;
    @Override
    protected void initPresenter() {
        mPresenter = new OrderPresenter(this,this);
    }

    @Override
    public void registerDate() {
        register(ReserveItem.class, new DEOrderBinder());
        register(CustomItem.class, new CustomOrderBinder());
        register(OrderEmptyItem.class, new OrderEmptyBinder());
    }

    @Override
    public void loadData() {
        if(extra.getType().equals(ReserveExtra.STYLE_DE)){
            mPresenter.getDEOrderList();
        } else {
            mPresenter.getCUOrderList();
        }
    }



    @Override
    protected void initTitle() {
        super.initTitle();
        extra = (ReserveExtra) getIntent().getSerializableExtra(ReserveExtra.getExtraName());
        String title="装修订单";
        if (extra != null) {
            if (extra.getType().equals(ReserveExtra.STYLE_DE)) {
                title = "装修订单";
            } else {
                title = "加配订单";
            }
        }
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText(title);
    }

    @Override
    public void initData() {
        super.initData();
        loadData();
        PayUtils.getInstance(this).setIPayListener(new PayUtils.IPayListener() {
            @Override
            public void onSuccess() {
                doRefresh();
            }

            @Override
            public void onFail() {

            }

            @Override
            public void onCancel() {

            }
        });
    }

    @Override
    public boolean onEmpty() {
        addData(new OrderEmptyItem());
        return true;
    }
}
